import {
	defineStore
} from 'pinia'
import {
	ref
} from "vue"

export const userStore = defineStore('user', {
	state: () => ({
		deviceId: "",
		info: {},
		topName: "云上归属",
		author: "qinhai269"
	}),
	getters: {
		topname(state) {
			return state.topName;
		},
		deivceId(state) {
			return state.deviceId;
		},
		checkInfo(state) {
			return state.info.name ? true : false;
		}
	},
	actions: {
		setDeviceId(id) {
			this.deviceId = id
		},
		setInfo(data) {
			this.info = data
		},
		logout() {
			this.info = {}
		}
	}
})

const msg = "欢迎使用批量归属地查询，复制微信消息直接粘贴，无需删除多余文字。微信内打开建议使用“微信浮窗”功能切换更方便。";

export const msgStore = defineStore('message', {
	state: () => ({
		data: [{
			from: "you",
			type: 'welcome',
			data: [],
			msg
		}]
	}),
	getters: {
		list(state) {
			return state.data;
		},
		len(state) {
			return state.data.length - 1
		}
	},
	actions: {
		add(data) {
			if (this.data.length >= 60) {
				this.data.shift()
			}
			this.data.push(data)
		},
		clear() {
			this.data = []
			this.data.push({
				from: "you",
				type: 'welcome',
				data: [],
				msg
			})
		},
		upStatus(index) {
			this.data[index].status = 0
		}
	}
})